<template>
  <div class="app-container-flex">
    <NewFullScreen
      v-model="showDialog"
      :title="title"
      @returnBack="$emit('returnModify')"
    >
      <template v-slot:full-button>
        <el-button @click="save()">保存</el-button>
      </template>
      <div class="model-panel">
        <div class="model-panel-title">
          <p>{{ $t('basic_information') }}</p>
        </div>
        <div class="model-panel-body">
          <!-- form -->
          <page-form
            class="paddingBox order-model-formBox flex_wrap_start_start"
            v-model:ref-obj="formInfo.ref"
            :disabled="formInfo.disabled"
            :data="formInfo.data"
            :field-list="formInfo.fieldList"
            :rules="formInfo.rules"
            :label-width="formInfo.labelWidth"
          >
            <template v-slot:form-crycle>
              <el-input-number
                v-model="formInfo.data.crycle"
                controls-position="right"
                :min="0"
                :max="999999999999999999"
                class="form-date"
              ></el-input-number>
              <select-model
                v-model.trim="formInfo.data.crycleType"
                typeCode="frequency_cycle"
                width="50%"
              />
            </template>
            <template v-slot:form-maintenancePrincipalValue>
              <el-input
                type="input"
                :disabled="true"
                class="not-mongolia"
                placeholder="请选择养护负责人"
                v-model="formInfo.data.maintenancePrincipalValue"
              >
                <template #append>
                  <el-icon @click="openUserWindow"><MoreFilled /></el-icon>
                </template>
              </el-input>
            </template>
            <template v-slot:form-remindTime>
              <span>任务开始前</span>
              <el-input-number
                v-model="formInfo.data.remindTime"
                controls-position="right"
                :min="0"
                :max="999999999999999999"
                style="width: 14%; display: inline-block"
              ></el-input-number>
              <select-model
                v-model.trim="formInfo.data.remind"
                typeCode="remind_time_type"
                width="14%"
              />
            </template>
            <template v-slot:form-remindTaskTime>
              <span>任务开始前</span>
              <el-input-number
                v-model="formInfo.data.remindTaskTime"
                controls-position="right"
                :min="0"
                :max="999999999999999999"
                style="width: 14%; display: inline-block"
              ></el-input-number>
              <select-model
                v-model.trim="formInfo.data.remindTask"
                typeCode="remind_time_type"
                width="14%"
              />
            </template>
            <template v-slot:form-planStartDate>
              <el-date-picker
                v-model="formInfo.data.planStartDate"
                type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss"
                placeholder="选择日期时间"
              >
              </el-date-picker>
            </template>
            <!-- <template v-slot:form-planEndDate>
              <el-date-picker
                v-model="formInfo.data.planEndDate"
                type="date"
                value-format="YYYY-MM-DD"
                :disabled-date="timePickerOptions.disabledDate"
                placeholder="选择日期"
              >
              </el-date-picker>
            </template> -->
            <template v-slot:form-filePathList>
              <upload-img
                v-model:value="formInfo.data.filePathList"
                multiple
                :action="action"
                :limit="10"
                :title="`附件`"
                :responseFn="handleResponse"
              />
            </template>
          </page-form>
        </div>
      </div>

      <div class="model-panel">
        <div class="model-panel-title">
          <Tooltip :text="'养护资产'" />
        </div>
        <div class="model-panel-body">
          <!-- 条件栏 -->
          <div v-if="!id">
            <NewPageFilter
              v-model:query="filterInfo.query"
              :filter-btn="filterInfo.list"
            >
              <template v-slot:filter-removeAsset>
                <el-button
                  :disabled="!tableInfo.selections.length"
                  @click="removeAsset()"
                  >删除资产</el-button
                >
              </template>
            </NewPageFilter>
            <div class="flex_full_item">
              <el-form :model="tableInfo" ref="tableForm" style="width: 100%">
                <!-- 表格 -->
                <page-table
                  :refresh="tableInfo.refresh"
                  :init-curpage="tableInfo.initCurpage"
                  v-model:data="tableInfo.data"
                  :pager="false"
                  :tabIndex="true"
                  :field-list="tableInfo.fieldList"
                  :handle="tableInfo.handle"
                  :row-class-name="tableRowClassName"
                  @handleEvent="handleEvent"
                >
                </page-table>
              </el-form>
            </div>
          </div>

          <page-form
            v-else
            class="paddingBox order-model-formBox flex_wrap_start_start"
            v-model:ref-obj="formInfo.ref"
            :disabled="formInfo.disabled"
            :data="formInfo.data"
            :field-list="formInfo.assetFieldList"
            :rules="formInfo.rules"
            :label-width="formInfo.labelWidth"
          >
          </page-form>
        </div>
      </div>

      <div class="model-panel">
        <div class="model-panel-title">
          <Tooltip :text="'养护项目'" />
        </div>
        <div class="model-panel-body">
          <!-- 条件栏 -->

          <NewPageFilter
            v-model:query="itemsFilterInfo.query"
            :filter-btn="itemsFilterInfo.list"
          >
            <template v-slot:filter-removeItem>
              <el-button
                :disabled="!itemsTableInfo.selections.length"
                @click="removeItem()"
                >删除项目</el-button
              >
            </template>
          </NewPageFilter>
          <div class="flex_full_item">
            <el-form
              :model="itemsTableInfo"
              ref="itemsTableForm"
              style="width: 100%"
            >
              <!-- 表格 -->
              <page-table
                :refresh="itemsTableInfo.refresh"
                :init-curpage="itemsTableInfo.initCurpage"
                v-model:data="itemsTableInfo.data"
                :pager="false"
                :tabIndex="true"
                :field-list="itemsTableInfo.fieldList"
                :handle="itemsTableInfo.handle"
                :row-class-name="tableRowClassName"
                @handleEvent="handleEventItems"
              >
                <template v-slot:col-maintenanceParts="scope">
                  <el-form-item
                    class="form-input"
                    :prop="`data.${scope.$index}.maintenanceParts`"
                    :rules="[
                      {
                        required: scope.$index > -1,
                        message: '请输入养护项目',
                        trigger: 'blur',
                      },
                    ]"
                  >
                    <el-input v-model="scope.row.maintenanceParts"> </el-input>
                  </el-form-item>
                </template>
                <template v-slot:col-contentRequire="scope">
                  <el-form-item
                    class="form-input"
                    :prop="`data.${scope.$index}.contentRequire`"
                    :rules="[
                      {
                        required: scope.$index > -1,
                        message: '请输入养护内容与要求',
                        trigger: 'blur',
                      },
                    ]"
                  >
                    <el-input v-model="scope.row.contentRequire"> </el-input>
                  </el-form-item>
                </template>
              </page-table>
            </el-form>
          </div>
        </div>
      </div>
    </NewFullScreen>

    <!-- 养护负责人 -->
    <SelectUsers
      v-if="selectUserInfo.visible"
      v-model:showDialog="selectUserInfo.visible"
      :api="getRrgUserList"
      :saveEmpty="true"
      :query="selectUserInfo.query"
      :check-box="false"
      :highlight-row="true"
      @callback="selectUserCallback"
    />
    <!--资产选择-->
    <Select-asset
      v-if="selectAssetInfo.visible"
      v-model:show-dialog="selectAssetInfo.visible"
      :tableKey="selectAssetInfo.tableKey"
      :query="selectAssetInfo.query.queryMap"
      :query-params="selectAssetInfo.query.queryParams"
      @callback="callBackAsset"
    />
    <SelectCustomizeTable
      v-if="selectCustomizeTableInfo.visible"
      v-model:visible="selectCustomizeTableInfo.visible"
      :api="selectCustomizeTableInfo.api"
      :query="selectCustomizeTableInfo.query"
      :tableKey="selectCustomizeTableInfo.tableKey"
      :defaultObj="selectCustomizeTableInfo.defaultObj"
      :checkBox="true"
      :highlightRow="false"
      title="选择养护模板"
      @callback="selectCustomizeTableCallback"
    />
  </div>
</template>

<script setup name="deviceMaintenancePlanModify">
import PageForm from '@/components/PageForm/index'
import PageTable from '@/components/PageTable/index'
import {
  createDeviceMaintenancePlan,
  updateDeviceMaintenancePlan,
  getDeviceMaintenancePlanById,
  getDeviceMaintenancePlanDetailList,
} from '@/api/repair'
import {
  getDeviceMaintenanceTemplateCustomizeListPage,
  getDeviceTemplateListByIds,
} from '@/api/device.js'
import { getUseReturnApplicationDetailCustomizeList } from '@/api/use'

import { getCustomizeSetting } from '@/api/customize'
import SelectModel from '@/components/SelectModel/index.vue'
import { getRrgUserList } from '@/api/base.js'
import SelectUsers from '@/components/SelectUsers/index'
import selectAsset from '@/components/SelectAsset/index'
import axios from 'axios'
const { proxy } = getCurrentInstance()
const emit = defineEmits()

const Tooltip = defineAsyncComponent(() => import('@/components/Tooltip/index'))

const props = defineProps(['visible', 'title', 'id'])
const action = ref(axios.defaults.baseURL + '/pub/uploadfile')

let validatePlanEndDate = (rule, value, callback) => {
  let planStartDate = formInfo.data.planStartDate

  if (planStartDate) {
    if (planStartDate > value) {
      callback(new Error('计划终止日期不能大于计划开始时间！'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}
let validatePlanStartDate = (rule, value, callback) => {
  let planEndDate = formInfo.data.planEndDate

  if (planEndDate) {
    if (planEndDate < value) {
      callback(new Error('计划开始时间不能小于计划终止日期！'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}
let validateRemindTask = (rule, value, callback) => {
  let remind = 0
  if (formInfo.data.remind == '1') {
    remind = 1
  } else if (formInfo.data.remind == '2') {
    remind = 60
  } else if (formInfo.data.remind == '3') {
    remind = 1440
  }
  let remindTask = 0
  if (formInfo.data.remindTask == '1') {
    remindTask = 1
  } else if (formInfo.data.remindTask == '2') {
    remindTask = 60
  } else if (formInfo.data.remindTask == '3') {
    remindTask = 1440
  }

  let remindTime = formInfo.data.remindTime || 0
  remindTime = remind * remindTime
  let remindTaskTime = formInfo.data.remindTaskTime || 0
  remindTaskTime = remindTaskTime * remindTask

  if (formInfo.data.remindTime) {
    let num = remindTaskTime - remindTime
    if (num < 5) {
      callback(new Error('任务创建时间必须大于提醒时间5分钟！'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}
let validateRemind = (rule, value, callback) => {
  let remind = 0
  if (formInfo.data.remind == '1') {
    remind = 1
  } else if (formInfo.data.remind == '2') {
    remind = 60
  } else if (formInfo.data.remind == '3') {
    remind = 1440
  }
  let remindTask = 0
  if (formInfo.data.remindTask == '1') {
    remindTask = 1
  } else if (formInfo.data.remindTask == '2') {
    remindTask = 60
  } else if (formInfo.data.remindTask == '3') {
    remindTask = 1440
  }

  let remindTime = formInfo.data.remindTime || 0
  remindTime = remind * remindTime
  let remindTaskTime = formInfo.data.remindTaskTime || 0
  remindTaskTime = remindTaskTime * remindTask
  if (formInfo.data.remindTaskTime) {
    let num = remindTaskTime - remindTime
    console.log(remindTaskTime, remindTime)
    if (num < 5) {
      callback(new Error('提醒时间必须小于任务创建时间5分钟！'))
    } else {
      callback()
    }
  } else {
    callback()
  }
}

const timePickerOptions = ref({})
const formRefs = ref([])
const formInfo = reactive({
  ref: null,
  data: {
    status: 0,
    remind: 1,
    remindTask: 1,
  },
  fieldList: [
    {
      label: '计划组名称',
      value: 'name',
      type: 'input',
      require: true,
      disabled: false,
    },
    {
      label: '养护类型',
      value: 'type',
      type: 'select-model',
      code: 'device_maintenance_type',
      require: true,
      disabled: false,
    },
    {
      label: '养护周期',
      value: 'crycle',
      type: 'slot',
      require: true,
    },
    {
      label: '养护负责人',
      value: 'maintenancePrincipalValue',
      type: 'slot',
      require: true,
    },
    {
      label: '计划开始时间',
      value: 'planStartDate',
      type: 'slot',
      require: true,
    },
    {
      label: '计划终止日期',
      value: 'planEndDate',
      type: 'date',
    },

    {
      label: '计划状态',
      value: 'status',
      type: 'radio-model',
      code: 'new_enabled_type',
      // disabled: false,
    },
    {
      label: '提醒于',
      value: 'remindTime',
      type: 'slot',
      className: 'not-br',
      require: true,
    },
    {
      label: '任务创建于',
      value: 'remindTaskTime',
      type: 'slot',
      className: 'not-br',
      require: true,
    },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
    },
    {
      label: '附件',
      value: 'filePathList',
      type: 'slot',
      className: 'not-br',
    },

  ],
  assetFieldList: [
    {
      label: '资产名称',
      value: 'assetName',
      type: 'input',
      disabled: true,
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      type: 'input',
      disabled: true,
    },
    {
      label: '规格',
      value: 'standard',
      type: 'input',
      disabled: true,
    },
    {
      label: '使用部门',
      value: 'useDeptName',
      type: 'input',
      disabled: true,
    },
  ],
  rules: {
    name: [{ required: true, message: '请输入计划组名称', trigger: 'blur' }],
    type: [{ required: true, message: '请选择养护类型', trigger: 'change' }],
    crycle: [{ required: true, message: '请输入养护周期', trigger: 'blur' }],
    maintenancePrincipalValue: [
      { required: true, message: '请选择养护负责人', trigger: 'change' },
    ],
    planStartDate: [
      {
        required: true,
        message: '请选择计划开始日期',
        trigger: 'change',
      },
      {
        validator: validatePlanEndDate,
        trigger: 'blur',
      },
    ],

    planEndDate: [
      {
        validator: validatePlanStartDate,
        trigger: 'blur',
      },
    ],
    remindTaskTime: [
      {
        validator: validateRemindTask,
        trigger: ['blur', 'change'],
      },
      {
        required: true,
        message: '请输入任务创建时间',
        trigger: 'blur',
      },
    ],
    remindTime: [
      {
        validator: validateRemind,
        trigger: ['blur', 'change'],
      },
      { required: true, message: '请输入提醒时间', trigger: 'blur' },
    ],
  },
  labelWidth: '120px',
})
// 养护资产过滤相关配置
const filterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
  },
  list: [
    { label: '添加资产', type: 'button', event: addAsset },
    { type: 'slot', value: 'removeAsset' },
  ],
})
// 养护资产表格相关
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],

  selections: [],

  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '删除',
        event: removeAsset,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
      },
    ],
  },
})
// 养护项目过滤相关配置
const itemsFilterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
  },
  list: [
    { label: '添加项目', type: 'button', event: addItem },
    { type: 'slot', value: 'removeItem' },
    { label: '模板添加', type: 'button', event: addTemplate },
  ],
})
// 养护项目表格相关
const itemsTableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  selections: [],
  query: {
    orderId: props.id,
    sort: 'create_time desc',
  },
  fieldList: [
    {
      label: '养护部位',
      value: 'maintenanceParts',
      type: 'slot',
    },
    {
      label: '养护内容与要求',
      value: 'contentRequire',
      type: 'slot',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '删除',
        event: removeItem,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
      },
    ],
  },
})
//选择资产资产
const selectAssetInfo = reactive({
  visible: false,
  tableKey:
    'deviceMaintenancePlanAsset-com.slip.spd.entity.vo.core.CoreAssetVO',
  query: {
    queryMap: {
      id: {
        queryType: 'NOT_IN',
        queryCategory: 'AND',
        value: '',
      },
      status: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '3',
      },
      assetStatus: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '1,3',
      },
      isMaintenance: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 1,
      },
      assetSourceAuth: {
        asTbName: 'core_asset,core_asset',
        columnName: 'use_dept_id,depot_id',
        queryType: 'IN',
        queryCategory: 'AND',
        value: 'assetSourceAuth',
      },

    },
    queryParams: {},
  },
})
const selectUserInfo = reactive({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectCustomizeTableInfo = ref({
  visible: false,
  api: getDeviceMaintenanceTemplateCustomizeListPage,
  query: {
    deptAuth: {
      asTbName: 'device_maintenance_template',
      columnName: 'dept_id',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'deptAuth',
    },
  },
  tableKey:
    'deviceMaintenanceTemplateList-com.slip.spd.entity.vo.device.maintenance.template.DeviceMaintenanceTemplateVO',
  defaultObj: {
    name: {
      label: '模板名称',
      value: 'name',
      componentType: 'input',
      show: false,
      hidden: true,
    },
  },
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})
watch(
  () => tableInfo.data,
  (val) => {
    if (val.length) {
      let ids = []
      val.forEach((item) => {
        ids.push(item.id)
      })
      selectAssetInfo.query.queryMap.id.value = String(ids)
    } else {
      selectAssetInfo.query.queryMap.id.value = ''
    }
  },
  { deep: true }
)
watch(
  () => formInfo.data.remind,
  (val) => {
    if (val && formInfo.data.remindTime) {
      formInfo.ref.validateField('remindTime', (errorMessage) => {
        console.log(errorMessage)
        // formInfo.fieldList[7].error = errorMessage
      })
    }
  },
  { deep: true }
)
watch(
  () => formInfo.data.remindTask,
  (val) => {
    if (val && formInfo.data.remindTaskTime) {
      formInfo.ref.validateField('remindTaskTime', (errorMessage) => {
        // formInfo.fieldList[8].error = errorMessage
      })
    }
  },
  { deep: true }
)

let obj = {
  assetName: {
    label: '资产名称',
    value: 'assetName',
    componentType: 'input',
    type: 'column',
    show: false,
    hidden: true,
  },
}
tableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...obj,
})
getCustomize()

onMounted(() => {
  timePickerOptions.value = {
    disabledDate(time) {
      return time.getTime() < Date.now() - 8.64e7
    },
  }
  formRefs.value = [proxy.$refs['itemsTableForm'], formInfo.ref]
  console.log(formRefs.value)
  proxy.$nextTick(() => {
    if (!props.id) {
      formInfo.fieldList = formInfo.fieldList.filter(
        (item) => item.value !== 'orderNo'
      )
    }
  })
})

//养护负责人
function openUserWindow() {
  selectUserInfo.visible = true
}
function selectUserCallback(row) {
  if (row) {
    formInfo.data['maintenancePrincipalValue'] = row.name
    formInfo.data['maintenancePrincipal'] = row.id
  } else {
    formInfo.data['maintenancePrincipalValue'] = ''
    formInfo.data['maintenancePrincipal'] = ''
  }
}

//添加资产
function addAsset() {
  selectAssetInfo.visible = true
}
//选择资产
function callBackAsset(data) {
  selectAssetInfo.visible = false
  if (data.length) {
    data.forEach((item) => {
      tableInfo.data.unshift(item)
    })
  }
}
//删除资产
function removeAsset(row = undefined) {
  if (row) {
    tableInfo.data = tableInfo.data.filter((item) => item !== row)
  } else {
    proxy
      .$confirm('删除后将改变数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        tableInfo.data = tableInfo.data.filter((row) => {
          return !tableInfo.selections.includes(row)
        })
      })
  }
}
//添加养护项目
function addItem() {
  let tableInfo = itemsTableInfo
  let obj = {
    maintenanceParts: '',
    contentRequire: '',
  }
  tableInfo.data.push(obj)
}

//删除养护项目
function removeItem(row = undefined) {
  let tableInfo = itemsTableInfo
  if (row) {
    tableInfo.data = tableInfo.data.filter((item) => item !== row)
  } else {
    proxy
      .$confirm('删除后将改变数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then(() => {
        tableInfo.data = tableInfo.data.filter((row) => {
          return !tableInfo.selections.includes(row)
        })
      })
  }
}
function addTemplate() {
  selectCustomizeTableInfo.value.visible = true
}
function selectCustomizeTableCallback(data) {
  if (data && data.length) {
    const ids = data.map((item) => item.id)
    getDeviceTemplateListByIds({
      idSet: ids
    }).then((res) => {
      itemsTableInfo.data = res.data
    })
  }
}
function tableRowClassName({ row = undefined }) {
  if (row.isChoice) {
    return 'success-row'
  } else {
    return ''
  }
}

function getList() {
  //修改请求明细信息

  getUseReturnApplicationDetailCustomizeList(filterInfo.query).then((resp) => {
    if (resp && resp.success && resp.data.length) {
      let data = resp.data
      data.forEach((item) => {
        //将返回的数据变成Map形式
        let key = []
        tableInfo.sysGroup.forEach((row) => {
          let obj = {}
          obj.columnName = row.columnName
          obj.asTbName = row.asTbName
          obj.value = item[row.key]
          key.push(obj)
        })
        item.key = JSON.stringify(key)
        tableInfo.map.set(item.key, item)
        if (!tableInfo.isSysGroup) {
          item.groupConcatDepotStockIds = item.depotStockId.toString()
          item.groupSize = 1
          let row = proxy.$fn.deepClone(item)
          delete row.key
          item.details = [row]
        }
        tableInfo.map.set(item.key, item)
      })
      tableInfo.data = data
    }
  })
}
function getMain() {
  getDeviceMaintenancePlanById(props.id).then((resp) => {
    if (resp && resp.success) {
      formInfo.data = resp.data
      formInfo.fieldList[0].disabled = true
      formInfo.fieldList[1].disabled = true
    }
  })
  filterInfo.query.queryMap.orderId.value = props.id
  // getList();
  getItemsList()
}
function getItemsList() {
  // itemsTableInfo.refresh = Math.random();
  getDeviceMaintenancePlanDetailList(itemsTableInfo.query).then((resp) => {
    if (resp && resp.success) {
      itemsTableInfo.data = resp.data
      // itemsTableInfo.fieldList[0].disabled = true;
      // itemsTableInfo.fieldList[1].disabled = true;
    }
  })
}
function getCustomize() {
  let param = {
    tableKey:
      'deviceMaintenancePlanAsset-com.slip.spd.entity.vo.core.CoreAssetVO',
  }
  tableInfo.isSysGroup = false
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      tableInfo.fieldList = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail
      )
      for (let key in data.detail) {
        if (data.detail[key].sysGroupLevel > 0) {
          tableInfo.isSysGroup = true
        }
      }
      filterInfo.query.customizeUserVO = data
    }
  })
  if (props.id) {
    getMain()
  }
}

// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.selections = data
      break
  }
}
function handleEventItems(event, data) {
  switch (event) {
    case 'tableCheck':
      itemsTableInfo.selections = data
      break
  }
}
function handleResponse(response, file) {
  return file
}

//保存
function save() {
  proxy.$fn
    .checkForm(formRefs.value)
    .then(() => {
      const data = formInfo.data
      data.assetIds = []
      if (tableInfo.data.length) {
        tableInfo.data.forEach((item) => {
          data.assetIds.push(item.id)
        })
      }
      data.deviceMaintenancePlanDetailVOList = itemsTableInfo.data
      const api = data.id
        ? updateDeviceMaintenancePlan
        : createDeviceMaintenancePlan
      console.log(api)
      api(data).then((resp) => {
        if (resp && resp.success) {
          showDialog.value = false
          emit('returnModify')
        }
      })
    })
    .catch((error) => {
      console.log(error)
    })
}
</script>

<style scoped>
.form-date {
  width: 50%;
  display: inline-block;
}
.form-date-type {
  width: 50%;
  display: inline-block;
}
.form-input {
  margin: 15px auto;
}
</style>
